//
//  SYPlayerViewController.m
//  SanYiTeaching
//
//  Created by 郑浩然 on 2019/4/18.
//  Copyright © 2019年 SanYi. All rights reserved.
//

#import "SYPlayerViewController.h"
#import "CLPlayerView.h"


@interface SYPlayerViewController ()

@property (nonatomic, strong) CLPlayerView *playerView;

@end

@implementation SYPlayerViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    
    CLPlayerView *playerView = [[CLPlayerView alloc] initWithFrame:CGRectMake(0, 0, kScreen_WIDTH, kScreen_HEIGHT)];
    
    _playerView = playerView;
    [self.view addSubview:_playerView];
    
    [_playerView updateWithConfigure:^(CLPlayerViewConfigure *configure) {
        //全屏是否隐藏状态栏，默认一直不隐藏
        configure.fullStatusBarHiddenType = FullStatusBarHiddenFollowToolBar;
        //后台返回是否继续播放
        configure.backPlay = NO;
        //转子颜色
        configure.strokeColor = [UIColor redColor];
        //工具条消失时间，默认10s
        configure.toolBarDisappearTime = 8;
        //全屏是否隐藏状态栏，默认一直不隐藏
        configure.topToolBarHiddenType = TopToolBarHiddenNever;
    }];
    //视频地址
  //  NSString *path = [[NSBundle mainBundle] pathForResource:@"video" ofType:@"mp4"];
    
    if (self.isPlayer) {
        _playerView.url =[NSURL fileURLWithPath:self.urlStr];
    } else {
        self.urlStr =  [self.urlStr stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
        _playerView.url = [NSURL URLWithString:self.urlStr];//[NSURL fileURLWithPath:path];
    }
    
    
    
    //播放
    [_playerView playVideo];
    //返回按钮点击事件回调,小屏状态才会调用，全屏默认变为小屏
    [_playerView backButton:^(UIButton *button) {
        
        [_playerView pausePlay];

        [_playerView destroyPlayer];
        [self dismissViewControllerAnimated:YES completion:nil];
    }];
    //播放完成回调
    [_playerView endPlay:^{
        NSLog(@"播放完成");
    }];
}
-(void)viewWillDisappear:(BOOL)animated{
    
    [super viewWillDisappear: animated];
    [_playerView pausePlay];

    [_playerView destroyPlayer];
}
-(void)viewDidDisappear:(BOOL)animated{
    
    [super viewDidDisappear:animated];
    
    [_playerView pausePlay];

    [_playerView destroyPlayer];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end














